Skip to content

fix: remote script#346

Merged
lazarv merged 1 commit into
mainfrom
fix/remote-script
Mar 8, 2026
Merged

fix: remote script#346
lazarv merged 1 commit into
mainfrom
fix/remote-script

Conversation

@lazarv

@lazarv lazarv commented Mar 8, 2026

Copy link
Copy Markdown
Owner

Problem

  1. React "Encountered a script tag" warning — Remote components returning <script> tags (e.g. import maps, __flightStream__ globals) caused React to warn during RSC rendering, since React's Float system does not allow <script> elements in JSX.

  2. "Each child in a list should have a unique key prop" warning — Live components ("use live") emitted spurious missing-key warnings for every keyless element, even when keys weren't required.

Root Cause

  1. dom-flight.mjs was passing <script> nodes through as regular JSX elements.

  2. The @lazarv/rsc custom Flight serializer had two issues:

    • It wrote debugCounter (an incrementing number) at position 6 of the dev element tuple, where React's Flight client expects _store.validated. This caused every deserialized element to have an incorrect validation state.
    • toStream/toBuffer never passed debug: true to the serializer, so it emitted 4-element production tuples. The dev-mode Flight client reads tuple[6] as undefined (= not validated), triggering key re-validation on all elements.

Changes

  • server/dom-flight.mjs — Convert <script> nodes to <template data-script-attrs> during Flight serialization to avoid React's script tag warning.
  • client/ReactServerComponent.jsx — Activate script templates (create real <script> elements from templates) before Flight hydration and on navigation, supporting both document and shadow DOM roots.
  • packages/rsc/server/shared.mjs — Emit element._store.validated (not debugCounter) at tuple position 6 in dev mode. Mark keyless Fragment children with validated = 2 to match React's renderFragment behavior.
  • cache/rsc.mjs / cache/rsc-browser.mjs — Pass debug: true in dev mode so the serializer emits full 7-element dev tuples with correct _store.validated values.
  • bin/commands/dev.mjs / lib/dev/create-server.mjs — Add --origin and --trust-proxy CLI options for reverse proxy support.
  • docs/ — Document the new --origin and --trust-proxy CLI options (en + ja).

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
react-server-docs d4faffc Mar 08 2026, 11:24 AM

@codecov-commenter

codecov-commenter commented Mar 8, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 83.33333% with 2 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (main@19d12eb). Learn more about missing BASE report.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
packages/rsc/server/shared.mjs 83.33% 2 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #346   +/-   ##
=======================================
  Coverage        ?   94.18%           
=======================================
  Files           ?        2           
  Lines           ?     2234           
  Branches        ?      677           
=======================================
  Hits            ?     2104           
  Misses          ?      130           
  Partials        ?        0           
Flag Coverage Δ
rsc 94.18% <83.33%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@lazarv lazarv merged commit baf0ab7 into main Mar 8, 2026
107 of 109 checks passed
@lazarv lazarv deleted the fix/remote-script branch March 8, 2026 14:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants